#include "Banana.h"

CBanana::CBanana(void)
{
	direction = true;
	dead = false;
	pickedUp = false;
}

CBanana::~CBanana(void)
{
}


void CBanana::Update()
{
	if(!dead){
	if(direction){
		if(tiles->canGoThere(x + 2.3, y, 26, 40) && (!tiles->canGoThere(x + 15.3, y + 5, 1, 64))){
			x+= 2.3;
		}
		else{
			direction = false;
		}
	}
	else{
		if(tiles->canGoThere(x - 2.3, y, 26, 40) && (!tiles->canGoThere(x + 9.3, y + 5, 1, 64))){
			x-= 2.3;
		}
		else{
			direction = true;
		}
	}
		int DifX = (((int)player->x) - ((int)x));
		int DifY = (((int)player->y) - ((int)y));

		
		
			if( DifX < 40 && (DifX > -40) && DifY < 0 && DifY >= -192 && player->waldoTime <= 0){
				CSoundPlayer::PlaySound1("music\\banana.wav");
				dead = true;
				bullets->NewBullet(x, y, 0, -2.3, player,0, false);
			}
		}


}
void CBanana::Init(int worldX, int worldY, CPlayer* playerPtr, Tiles* tilesPtr)
{
	health = 100;
	x = worldX;
	y = worldY;

	height = 64;
	width = 32;
	tiles= tilesPtr;

	char picfile[] = "res/banana.bmp";
	hImage = LoadImage(NULL, picfile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

		char picfile1[] = "res/bananapeel.bmp";
	peel = LoadImage(NULL, picfile1, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

	//bufDC = CreateCompatibleDC(graphics);
	//bufBMP = CreateCompatibleBitmap(graphics, rect.right, rect.bottom);
	//SelectObject(bufDC, bufBMP);
	//::FillRect(bufDC, &rect, ::CreateSolidBrush(0x00FFFFFF));

	player = playerPtr;
}

void CBanana::Draw(HDC graphics)
{
	if(!dead){
		RenderHelper::RenderBitmap(graphics, hImage, x,y, width, height);
	}
	else{
		RenderHelper::RenderBitmap(graphics, peel, x,y + 32, width, 32);
	}
}